package com.pinyougou.manager.controller;

import java.util.List;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.IBrandService;

import entity.PageResult;
import entity.Result;

@RestController
@RequestMapping("/brand")
public class BrandController {

	@Reference
	private IBrandService brandService;
	
	@RequestMapping("/findAllBrand")
	public List<TbBrand> findAllBrand(){
		return brandService.findAllBrand();
	}
	
	/**
	 * 分页查询所有品牌信息，包括模糊查询
	 * 
	 * @param brand		模糊查询的条件	
	 * @param pageNum	当前页
	 * @param pageSize	每页显示条数
	 * @return
	 */
	@RequestMapping("/findPageAll")
	public PageResult findPageAll(@RequestBody TbBrand brand,Integer pageNum,Integer pageSize) {
		return brandService.findPageAll(brand, pageNum, pageSize);
	}
	
	/**
	 * 添加品牌信息
	 * 
	 * @param brand 添加的品牌信息
	 */
	@RequestMapping("/addBrand")
	public Result addBrand(@RequestBody TbBrand brand) {
		try {
			brandService.addBrand(brand);
			return new Result(true, "添加成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "添加失败");
		}
	}
	
	/**
	 * 删除品牌信息
	 * 
	 * @param ids	品牌ID
	 * @return
	 */
	@RequestMapping("/deleteBrand")
	public Result deleteBrand(@RequestBody Long[] ids) {
		try {
			brandService.deleteBrand(ids);
			return new Result(true, "删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "删除失败");
		}
	}
	
	/**
	 * 根据品牌ID查询品牌信息
	 * 
	 * @param id	品牌ID
	 * @return
	 */
	@RequestMapping("/findByBrandId")
	public TbBrand findByBrandId(Long id) {
		return brandService.findByBrandId(id);
	}
	
	/**
	 * 修改品牌信息
	 * 
	 * @param brand	品牌参数
	 * @return
	 */
	@RequestMapping("/updateBrand")
	public Result updateBrand(@RequestBody TbBrand brand) {
		try {
			brandService.updateBrand(brand);;
			return new Result(true, "删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "删除失败");
		}
	}
	
	
}
